/**
 *    Copyright 2006-2017 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.mybatis.generator.plugins.custome;

import java.io.Serializable;

/**
 * Created by zuosh on 2016/4/29 0029.
 * 简单不分页数据返回所用结构
 */
public class ResponseHelper implements Serializable {
    /**
     * desc by kai
     * [ 返回结果集 ]
     */
    public static <T> RestResponse <T> buildResponse(String code, T data, String msg) {
        return new RestResponse(code, data, msg);
    }

    public static <T> RestResponse buildResponse(String code, T data) {
        return new RestResponse(code, data, null);
    }

    public static RestResponse buildResponse(String code) {
        return new RestResponse(code, null, null);
    }

    public static RestResponse buildResponse(String code, String msg) {
        return new RestResponse(code, null, msg);
    }

    public static class RestResponse<T> implements Serializable {
        private String code = RestResponseCode._200;//默认返回200
        private T data;
        private String msg;//请求结果说明

        public RestResponse(String code, T data, String msg) {
            this.code = code;
            this.data = data;
            this.msg = msg;
        }

        public String getCode() {
            return code;
        }

        public T getData() {
            return data;
        }

        public String getMsg() {
            return msg;
        }
    }

}
